//
//  UFType.m
//  Ufan
//
//  Created by yangqingluo on 15/11/10.
//  Copyright © 2015年 yangqingluo. All rights reserved.
//

#import "UFType.h"

@implementation UFType

@end



@implementation UFProduct

NSArray *productsFromArray(NSArray *array){
    NSMutableArray *productsArray = [NSMutableArray new];
    
    for (NSDictionary *productnDic in array) {
        [productsArray addObject:productFromDic(productnDic)];
    }
    
    return productsArray.count ? [NSArray arrayWithArray:productsArray] : nil;
}
UFProduct *productFromDic(NSDictionary *dic){
    if (!dic) {
        return nil;
    }
    UFProduct *product = [UFProduct new];
    
    product.idString = [dic objectForKey:@"id"];
    product.name = [dic objectForKey:@"name"];
    product.price = [dic objectForKey:@"price"];
    product.mainUrl = [dic objectForKey:@"mainUrl"];
    
    product.inventory = [[dic objectForKey:@"inventory"] intValue];
    product.saledNum = [[dic objectForKey:@"saledNum"] intValue];
    product.hot = [dic objectForKey:@"hot"];
    product.reserve = [dic objectForKey:@"reserve"];

    product.saledNum = [dic[@"saledNum"] intValue];
    product.sellerLoad = [dic[@"sellerLoad"] intValue];
    
    return product;
}

@end



@implementation UFProductSell

NSArray *productSellsFromArray(NSArray *array){
    NSMutableArray *productsArray = [NSMutableArray new];
    
    for (NSDictionary *productnDic in array) {
        [productsArray addObject:productSellFromDic(productnDic)];
    }
    
    return productsArray.count ? [NSArray arrayWithArray:productsArray] : nil;
}
UFProductSell *productSellFromDic(NSDictionary *dic){
    if (!dic) {
        return nil;
    }
    UFProductSell *product = [UFProductSell new];
    
    product.idString = [dic objectForKey:@"id"];
    product.name = [dic objectForKey:@"name"];
    product.price = [dic objectForKey:@"price"];
    product.mainUrl = [dic objectForKey:@"mainUrl"];
    
    product.inventory = [[dic objectForKey:@"inventory"] intValue];
    product.saledNum = [[dic objectForKey:@"saledNum"] intValue];
    product.hot = [dic objectForKey:@"hot"];
    product.reserve = [dic objectForKey:@"reserve"];
    
    product.orderCount = [dic[@"orderCount"] intValue];
    product.starCount = [dic[@"starCount"] intValue];
    
    return product;
}

@end


@implementation UFSupplier

UFSupplier * supplierFormDic(NSDictionary *dic){
    if (!dic) {
        return nil;
    }
    
    UFSupplier *supplier = [UFSupplier new];
    
    supplier.descriptionString = dic[@"description"];
    supplier.name = dic[@"name"];
    supplier.logoUrl = dic[@"logoUrl"];
    supplier.siteUrl = dic[@"siteUrl"];
    supplier.shippingStatusShipped = dic[@"shippingStatusShipped"];
    supplier.shippingStatusToBeShipped = dic[@"shippingStatusToBeShipped"];
    supplier.shippingStatusReceiving = dic[@"shippingStatusReceiving"];
    supplier.orderStatusConfirmed = dic[@"orderStatusConfirmed"];
    supplier.orderStatusToBeConfirmed = dic[@"orderStatusToBeConfirmed"];
    supplier.orderStatusCompleted = dic[@"orderStatusCompleted"];
    supplier.orderStatusCancelled = dic[@"orderStatusCancelled"];
    supplier.paymentStatusUnpaid = dic[@"paymentStatusUnpaid"];
    supplier.paymentStatusPaid = dic[@"paymentStatusPaid"];
    supplier.refund_STATUS_COMPLETED = dic[@"refund_STATUS_COMPLETED"];
    supplier.refund_STATUS_FAILURE = dic[@"refund_STATUS_FAILURE"];
    supplier.refund_STATUS_NO_REFUND = dic[@"refund_STATUS_NO_REFUND"];
    supplier.refund_STATUS_REFUND = dic[@"refund_STATUS_REFUND"];
    
    return supplier;
}
@end

@implementation UFItem

UFItem *itemFromDic(NSDictionary *dic){
    if (!dic) {
        return nil;
    }
    
    UFItem *item = [UFItem new];
    
    item.saleEarning = [dic[@"saleEarning"] intValue];
    item.samplePrice = [dic[@"samplePrice"] doubleValue];
    item.inventory = [dic[@"inventory"] intValue];
    item.retailPrice = [dic[@"retailPrice"] doubleValue];
    item.name = dic[@"name"];
    item.idString = dic[@"id"];
    
    return item;
}

@end

@implementation UFCategory

UFCategory * categoryFormDic(NSDictionary *dic){
    if (!dic) {
        return nil;
    }
    
    UFCategory *category = [UFCategory new];
    
    category.descriptionString = dic[@"description"];
    category.idString = dic[@"id"];
    category.isRoot = [dic[@"isRoot"] boolValue];
    category.name = dic[@"name"];
    category.parentId = [dic[@"parentId"] intValue];
    category.sort = [dic[@"sort"] intValue];
    
    return category;
}


@end

@implementation UFImage

NSArray *ufimagesFromArray(NSArray *array){
    NSMutableArray *imagesArray = [NSMutableArray new];
    
    for (NSDictionary *imageDic in array) {
        [imagesArray addObject:ufimageFromDic(imageDic)];
    }
    
    return imagesArray.count ? [NSArray arrayWithArray:imagesArray] : nil;
}
UFImage *ufimageFromDic(NSDictionary *dic){
    if (!dic) {
        return nil;
    }
    
    UFImage *image = [UFImage new];
    
    image.displayOrder = [dic[@"displayOrder"] intValue];
    image.idString = dic[@"id"];
    image.name = dic[@"name"];
    image.url = dic[@"url"];
    image.urlPath = dic[@"urlPath"];
    
    return image;
}

@end

@implementation UFItemTitle

NSArray *itemTitleListFromArray(NSArray *array){
    NSMutableArray *itemTitlesArray = [NSMutableArray new];
    
    for (NSDictionary *itemTitleDic in array) {
        [itemTitlesArray addObject:itemTitleFromDic(itemTitleDic)];
    }
    
    return itemTitlesArray.count ? [NSArray arrayWithArray:itemTitlesArray] : nil;
}

UFItemTitle *itemTitleFromDic(NSDictionary *dic){
    if (!dic) {
        return nil;
    }
    
    UFItemTitle *itemTitle = [UFItemTitle new];
    
    itemTitle.name = dic[@"name"];
    itemTitle.title = dic[@"title"];
    itemTitle.value = dic[@"value"];
    
    return itemTitle;
}


@end


@implementation UFProductInfo

UFProductInfo *productInfoFormDic(NSDictionary *dic){
    if (!dic) {
        return nil;
    }
    
    UFProductInfo *productInfo = [UFProductInfo new];
    
    productInfo.category = categoryFormDic(dic[@"category"]);
    productInfo.descriptionString = dic[@"description"];
    productInfo.idString = dic[@"id"];
    productInfo.imageList = ufimagesFromArray(dic[@"imageList"]);
    productInfo.inventory = [dic[@"inventory"] intValue];
    productInfo.isCollect = [dic[@"isCollect"] boolValue];
    productInfo.isDownLoad = [dic[@"isDownLoad"] boolValue];
    productInfo.itemList = dic[@"itemList"];
    productInfo.itemTitleList = itemTitleListFromArray(dic[@"itemTitleList"]);
    productInfo.name = dic[@"name"];
    productInfo.price = dic[@"price"];
    productInfo.productCollectCount = [dic[@"productCollectCount"] intValue];
    productInfo.propertyList = dic[@"propertyList"];
    productInfo.saledNum = [dic[@"saledNum"] intValue];
    productInfo.supplier = supplierFormDic(dic[@"supplier"]);
    productInfo.intro = dic[@"intro"];
    
    return productInfo;
}

UFProductInfo *productInfoFormProduct(UFProduct *pro){
    if (!pro) {
        return nil;
    }
    
    UFProductInfo *productInfo = [UFProductInfo new];
    
    productInfo.idString = pro.idString;
    productInfo.inventory = pro.inventory;
    productInfo.name = pro.name;
    productInfo.price = pro.price;
    productInfo.saledNum = pro.saledNum;
    
    return productInfo;
}

@end

@implementation UFInvoice



@end

@implementation UFShoppingProduct



@end

@implementation UFShoppingInfo



@end


@implementation UFAddressInfo

NSArray *addressesFromArray(NSArray *array){
    NSMutableArray *addressArray = [NSMutableArray new];
    
    for (NSDictionary *addressDic in array) {
        [addressArray addObject:addressFromDic(addressDic)];
    }
    
    return addressArray.count ? [NSArray arrayWithArray:addressArray] : nil;
}

UFAddressInfo *addressFromDic(NSDictionary *dic){
    if (!dic) {
        return nil;
    }
    
    UFAddressInfo *addressInfo = [UFAddressInfo new];
    addressInfo.idString = dic[@"id"];
    addressInfo.detailAddress = dic[@"detailAddress"];
    addressInfo.name = dic[@"name"];
    addressInfo.deliveryName = dic[@"deliveryName"];
    addressInfo.deliveryPhone = dic[@"deliveryPhone"];
    addressInfo.def = [dic[@"def"] boolValue];
    
    return addressInfo;
}

@end

@implementation UFOrderInfo

NSArray *ordersFromArray(NSArray *array){
    NSMutableArray *orderArray = [NSMutableArray new];
    
    for (NSDictionary *orderDic in array) {
        [orderArray addObject:orderFromDic(orderDic)];
    }
    
    return orderArray.count ? [NSArray arrayWithArray:orderArray] : nil;
}
UFOrderInfo *orderFromDic(NSDictionary *dic){
    if (!dic) {
        return nil;
    }
    
    UFOrderInfo *info = [UFOrderInfo new];
    
    info.idString = dic[@"id"];
    info.orderNum = dic[@"orderNum"];
    info.createDate = [dic[@"createDate"] doubleValue] * 0.001;
    info.totalPrice = [dic[@"totalPrice"] doubleValue];
    info.receiveUserName = dic[@"receiveUserName"];
    info.city = dic[@"city"];
    info.paymentId = dic[@"paymentId"];
    info.province = dic[@"province"];
    info.district = dic[@"district"];
    info.receiveDetailAddress = dic[@"receiveDetailAddress"];
    info.receivePhoneNum = dic[@"receivePhoneNum"];
    info.totalProductNum = [dic[@"totalProductNum"] intValue];
    info.reFundcount = [dic[@"reFundcount"] intValue];
    info.orderType = [dic[@"orderType"] intValue];
    info.productType = dic[@"productType"];
    info.productItems = productItemsFromArray(dic[@"productItems"]);
    info.orderShips = shipsFromArray(dic[@"orderShips"]);
    
    return info;
}

@end


@implementation UFProductItem


NSArray *productItemsFromArray(NSArray *array){
    NSMutableArray *productItemArray = [NSMutableArray new];
    
    for (NSDictionary *productItemDic in array) {
        [productItemArray addObject:productItemFromDic(productItemDic)];
    }
    
    return productItemArray.count ? [NSArray arrayWithArray:productItemArray] : nil;
}

UFProductItem *productItemFromDic(NSDictionary *dic){
    if (!dic) {
        return nil;
    }
    
    UFProductItem *productItem = [UFProductItem new];
    
    productItem.productItemId = dic[@"productItemId"];
    productItem.levelUrl = dic[@"levelUrl"];
    productItem.orderItemId = dic[@"orderItemId"];
    productItem.productName = dic[@"productName"];
    productItem.itemName = dic[@"itemName"];
    productItem.itemPrice = [dic[@"itemPrice"] doubleValue];
    productItem.quantity = [dic[@"quantity"] intValue];
    productItem.mainUrl = dic[@"mainUrl"];
    productItem.itemSaleEarning = [dic[@"itemSaleEarning"] intValue];
    productItem.itemBonusEarning = [dic[@"itemBonusEarning"] intValue];
    productItem.allreFundStatus = dic[@"allreFundStatus"];
    productItem.checkRefundStatus = dic[@"checkRefundStatus"];
    productItem.type = dic[@"type"];
    productItem.productType = dic[@"productType"];

    
    return productItem;
}


@end


@implementation UFPayStyle

UFPayStyle *payStyleMake(NSString *make_id, NSString *make_name, NSString *make_imagename, BOOL make_selected){
    UFPayStyle *style = [UFPayStyle new];
    
    style.idString = [make_id copy];
    style.name = [make_name copy];
    style.imageName = [make_imagename copy];
    style.selected = make_selected;
    
    return style;
}

@end


@implementation UFShipInfo

NSArray *shipsFromArray(NSArray *array){
    NSMutableArray *shipArray = [NSMutableArray new];
    
    for (NSDictionary *shipDic in array) {
        [shipArray addObject:shipFromDic(shipDic)];
    }
    
    return shipArray.count ? [NSArray arrayWithArray:shipArray] : nil;
    
}
UFShipInfo *shipFromDic(NSDictionary *dic){
    if (!dic) {
        return nil;
    }
    
    UFShipInfo *info = [UFShipInfo new];
    
    info.idString = dic[@"id"];
    info.note = dic[@"note"];
    info.operBy = dic[@"operBy"];
    info.orderId = dic[@"orderId"];
    info.shippedDate = [dic[@"shippedDate"] doubleValue] * 0.001;
    info.shippedNum = dic[@"shippedNum"];
    info.shipper = dic[@"shipper"];
    
    return info;
}

@end
